package main

import (
	"fmt"
	"sync"
)

func main()  {
	var mux sync.WaitGroup
	ch := make(chan int)

	mux.Add(2)
	go func() {
		defer mux.Done()
		for i:=0; i<5;i++  {
			ch <- i
		}
		close(ch)
	}()

	go func() {
		defer mux.Done()
		for v := range ch{
			fmt.Println(v)
		}
	}()

	mux.Wait()
}
